﻿jQuery("document").ready(function($){
/* fix slider width */
if($(".slider").length>0)
{
	var sliderwidth = $(".detail").width() - $(".info").width() - 20 - 1; /* margin right is 20 */
	$(".slider").css("width", sliderwidth + "px").show();
	$(".sliderwrapper").css("width", sliderwidth + "px").show();
	var sleft,sright;
	$(".slideleft").bind("mouseover",function(e){
	   sleft = setInterval("scrollleft()",10); 
	}).bind("mouseout",function(e){
	    clearInterval(sleft);
	});
	$(".slideright").bind("mouseover",function(e){
	    sright = setInterval("scrollright()",10); 
	}).bind("mouseout",function(e){
	    clearInterval(sright);
	});
}
function bindFancybox()
{
    $(".slides_container div a").fancybox({
	    'transitionIn'	:	'elastic',
	    'transitionOut'	:	'elastic',
	    'speedIn'		:	600, 
	    'speedOut'		:	200, 
	    'overlayShow'	:	true
    });
}
bindFancybox();
if(preloadimgs!=null && preloadlinks!=null)
{
    if(preloadimgs.length > 0 && preloadlinks.length>0)	preload(0);
}
function preload(index)
{
	$.loadImages(preloadimgs[index],function(){
		var newitem = $("<div class=\"slideritem\"><a rel=\"Gallery\" href=\"" + preloadlinks[index] + "\"><img src=\"" + preloadimgs[index] +"\" /></a></div>");
		newitem.hide().appendTo($(".slides_container")).show();
		if(index<preloadimgs.length) preload(index+1);
		bindFancybox();
	});
}
});
//end jquery ready
function scrollleft()
{
    var $s = $(".slider");
    var nextscroll = $s.scrollLeft()-2;
    if(nextscroll<0) nextscroll = 0;
    console.log(nextscroll);
    $s.scrollLeft(nextscroll);
}
function scrollright()
{
    var $s = $(".slider");
    var nextscroll = $s.scrollLeft()+2;
    var maxmove = 0;
    $(".slideritem").each(function(){
        maxmove += $(this).width();
    });
    maxmove -= $(".slideritem:last").width();
    console.log(maxmove-nextscroll);
    if(maxmove-nextscroll>0) $s.scrollLeft(nextscroll);
}